package itsur.arquitecturas.implicitinvocation;

/**************************************************************************************
** Class name: StudentList
** Author: A.J. Lattanze
** Date: 12/29/99
** Version 1.0
***************************************************************************************
** Purpose: Assignment 3 for SE 17-655, Architectures for Software Systems. This class
** is used by various other classes that need to keep a list of students on hand.  This
** class extends the List class which provides the basic functionality for storage and
** retrieval of the Student Object from the list.
** (reused from assignment 2)
**
** Abstract: The StudentList class provides the following methods:
**
**	void AddStudent( Student Obj ) - Adds a new student to the list. All the issues
**	of casting are taken care of within this class.
**
**	boolean FindStudent( Student Obj ) - Determines whether the Student OBJ is
**	currently in the student list.  If the student is in the list, a true is
**	returned, otherwise a false boolean value is returned.
**
**	Student Obj = GetNextStudent() - Returns the student pointed at the current
**	position pointed to by the internal list pointer of the internal list. Subsequent
**	calls will return the next student object in the list.  A null object is returned
**	if list is empty or the end of list has been reached.
**
**	public Student FindStudentByID( String StudentID ) - Finds a student in a list
** 	using the StudentID as the search key.  If the current list object's StudentID
**	matches the StudentID passed to the method, the Student object is returned to
**	the caller.  If there is no match, null is returned to the caller.
**
** Modification Log
**************************************************************************************
**
**************************************************************************************/

class StudentList extends List
{
	public void AddStudent( Student StudentObject )
	{
		AppendItemToList( (Object) StudentObject );

	} // AddStudent


	public Student GetNextStudent()
	{
		return (Student) GetItemFromList();

	} // GetNextStudent

	public boolean FindStudent( Student StudentObject )
	{
		Student CurrentObject;
		boolean Done = false;
		boolean Result = false;

		// Note that this method assumes that all students have different
		// identification numbers.

		GoToFrontOfList();

		while (!Done )
		{
		   CurrentObject = GetNextStudent();

		   if ( CurrentObject == null )
		   {
			Done = true;

		   } else {
		 	if ( StudentObject.StudentID.compareTo( CurrentObject.StudentID ) == 0 )
			{
		 	   Result = true;

			} // if
		   } // if
		} // while

		return( Result );

	} // FindStudent


	public Student FindStudentByID( String StudentID )
	{
		Student CurrentObject = null;
		boolean Done = false;
		boolean Found = false;

		// Note that this method assumes that all courses have different
		// identification numbers.

		GoToFrontOfList();

		while (!Done )
		{
		   CurrentObject = GetNextStudent();

		   if ( CurrentObject == null )
		   {
			Done = true;

		   } else {
		 	if ( CurrentObject.StudentID.compareTo( StudentID ) == 0 )
			{
		 	   Found = true;
			   Done = true;

			} // if
		   } // if
		} // while

		if ( Found )
		{
			return( CurrentObject );

		} else {

			return( null );

		} // if

	} // FindStudentByID

} //StudentList